package com.sync.syncmasterdata.product.repository.u8;

import com.sync.syncmasterdata.product.entity.u8.Inventory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Map;

@Repository
public interface InventoryRepository extends JpaRepository<Inventory,String> {

//    @Query(nativeQuery = true, value= "select top 1 cInvCode,cInvStd,cInvAddCode,cInvCCode from UFDATA_111_2018..Inventory where substring(cInvCode,1,:len)=:cInvCode  order by I_id desc")
    @Query(nativeQuery = true, value= "select top 1 cInvCode,cInvStd,cInvAddCode,cInvCCode from Inventory where substring(cInvCode,1,:len)=:cInvCode  order by I_id desc")
    Inventory findLatestBycinvCCode(@Param(value = "cInvCode") String cInvCode,@Param(value="len") Integer len);

    /**
     * 获取 某分类 当前的序号列表
     * @param cInvCode
     * @param len
     * @return
     */
    @Query(nativeQuery = true, value= "select substring(cInvCode,5,len(cinvcode)) as substr from Inventory where substring(cInvCode,1,:len)=:cInvCode  order by I_id desc")
    List<String> findBycinvcCode(@Param(value = "cInvCode") String cInvCode, @Param(value="len") Integer len);

    /**
     * 获取 U8实例对象 by code
     * @param cInvCode
     * @return
     */
    @Query(nativeQuery = true, value = "select top 1 cInvCode,cInvStd,cInvAddCode,cInvCCode from Inventory where cInvCode=:cInvCode")
    Inventory hasProductByCode(@Param(value = "cInvCode") String cInvCode);



}